Hi Guys,
I have written a powershell code and it requires some tweaking. All the values are being returned fine however emailaddresses is being coming as system.object[] how can i get the value to be outputted in csv format. I appreciate if someone can review and
point out the error.
################################################################################## # Powershell Script for Mailbox Data Collection # by Navdeep www.Alivebits.com # Date 09 Jan 2015 version 1.0 Baseline # Date 08 Feb 2015 version 1.1 Added Mailbox Statistics # Date 29 June 2015 version 1.2 Updated Columns Database to ExchDB, WhenDataCol to # DataCollectionDate, mailbox size will return in MBs ################################################################################## # Import Modules needed for Script Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 Set-AdServerSettings -viewEntireForest $true $StartDate = get-date -format g $sheetname= get-date -format "dd MMMM yyyy" $sheetname.ToString() <# Get-Mailbox -Resultsize unlimited | Select DisplayName, PrimarySMTPAddress, @{Name=EmailAddresses;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq smtp} | ForEach-Object {$_.SmtpAddress}}}, SamAccountName, ServerName, Database, Office, WhenMailboxCreated,@{Name="WhenDataCol"; Expression={$startDate}}, OrganizationalUnit | Export-CSV -Path C:\Users\exch2013\Documents\MailboxReport\MailboxReport_$sheetname.csv #> $DataPath = "C:\Users\PROFILE\Documents\MailboxReport\MailboxReport_$sheetname.csv" $Results = @() $MailboxUsers = get-mailbox -resultsize unlimited foreach($user in $mailboxusers) { $UPN = $user.userprincipalname $DN = $User.DisplayName $PSMTP = $User.PrimarySMTPAddress $EmailAddresses = $user.EmailAddresses | Where-Object {$_.PrefixString -ceq smtp} | ForEach-Object {$_.SmtpAddress} $sAccName = $user.SamAccountName $SN = $User.ServerName $DB = $user.database $OU = $user.OrganizationalUnit $Office = $user.office $MailboxCreated = $user.WhenCreated if($user.ProhibitSendQuota -eq 'unlimited') { $Quota=$user.ProhibitSendQuota } else { $Quota=$user.ProhibitSendQuota.value.ToMB() } $MbxStats = Get-MailboxStatistics $UPN $Properties = @{ DisplayName = $DN Office = $Office OrganizationalUnit = $OU PrimarySMTPAddress = $PSMTP EmailAddresses = $EmailAddresses SamAccountName = $sAccName ServerName = $SN ExchDB = $DB ProhibitSendQuota = $Quota TotalItemCount = $MbxStats.ItemCount TotalItemSize = $MbxStats.TotalItemSize.value.ToMB() MailboxCreated = $MailboxCreated LastLogonTime = $MbxStats.LastLogonTime DataCollectionDate = $startDate } $Results += New-Object psobject -Property $properties } $Results | Select-Object DisplayName,Office,OrganizationalUnit,PrimarySMTPAddress,EmailAddresses,SamAccountName,ServerName,ExchDB,ProhibitSendQuota,TotalItemSize,MailboxCreated,LastLogonTime,DataCollectionDate | Export-Csv -notypeinformation -Path $DataPath